package com.sziit.se.highconcurrency.user.application.controller;

import com.sziit.se.highconcurrency.common.entity.LoginRsp;
import com.sziit.se.highconcurrency.common.result.Result;
import com.sziit.se.highconcurrency.common.result.ResultUtil;
import com.sziit.se.highconcurrency.common.service.IUserService;
import com.sziit.se.highconcurrency.common.entity.UserInfoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/account")
public class UserAccountController {

    private final IUserService userService;

    @PostMapping("/register")

    public Result register(@RequestParam String userName, String password, String phone) {
        Boolean registered = userService.insertUser(userName, password, phone);
        return ResultUtil.auto(registered);
    }

    @PostMapping("/login")
    public Result login(String userName, String password) {
        LoginRsp loginRsp = userService.login(userName, password);
        return ResultUtil.data(loginRsp);
    }

    @GetMapping("/info")
    public Result userInfo() {
        UserInfoVo userInfoVo = userService.userInfo();
        return ResultUtil.data(userInfoVo);
    }

    @PutMapping("/update/user")

    public Result updateUser(String userName, String password, String phone) {
        UserInfoVo userInfoVo = userService.updateUser(userName, password, phone);
        return ResultUtil.data(userInfoVo);
    }

}
